package com.exam.meituan;

import java.util.Arrays;
import java.util.Scanner;

/**
 * date:
 * description:
 */
public class Solution002 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = scanner.nextInt();
        }
        int res = cummulate(nums);
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                int[] ret = reverse(nums, i, j);
                int output = cummulate(ret);
                res = Math.max(res, output);
            }
        }
        System.out.println(res);
    }

    public static int[] reverse(int[] nums, int left, int right) {
        if(left >= right){
            return nums;
        }
        int[] ret = Arrays.copyOfRange(nums, 0, nums.length);
        int i = left, j = right;
        while(i < j){
            int tmp = ret[i];
            ret[i] = ret[j];
            ret[j] = tmp;
            i++;
            j--;
        }
        return ret;
    }

    public static int cummulate(int[] ret){
        int pre = ret[0], res = ret[0];
        for (int i = 1; i < ret.length; i++) {
            pre = Math.max(ret[i], ret[i] + pre);
            res = Math.max(res, pre);
        }
        return res;
    }
}
